import pdf from 'vue-pdf'
import {mapState} from "vuex";
import roomTable from './components/property_form.vue'
import {uploadContractFile} from '../api/room.js';

export default {
    name: "ocr-add",
    components: {pdf, roomTable},
    data() {
        return {
            dialogVisible: false,
            roomFile: null,
            pdfUrl: "",
            contractUrl:"",
            dialogContractVisible: false,
        }
    },
    methods: {
        show() {
            this.dialogVisible = true;
        },
        handleClose(done) {
            this.$confirm('确认关闭？').then(_ => {
                    done();
                })
        },
        // 识别文件
        getFile(event) {
            this.roomFile = event.target.files[0];
        },

        //上传附件
        upload() {
            if (this.roomFile == null) {
                this.$alert("请先选择文件，再上传");
                return;
            }

            let formData = new FormData();
            formData.append('file', this.roomFile);

            //export function uploadContractFile(obj) {
            //     return request({
            //         url: '/admin/sys-file/upload',
            //         method: 'post',
            //         data:obj
            //     })
            // }
            uploadContractFile(formData).then(response => {
                if (response.data.code == 0) {
                    this.$alert("上传附件成功");
                    //this.$alert(window.location.origin);
                    //this.$alert(response.data.data.url);
                    this.pdfUrl = window.location.origin + response.data.data.url;

                    this.contractUrl = response.data.data.url;
                    console.log()
                    //alert(this.formData.pdfUrl);
                    //this.formData.contractName=this.contractName;

                } else {
                    this.$alert("服务端异常：" + response.message);
                }
            })

        },
        read() {

            this.$refs.roomTable.$refs.baseData.baseForm = {
                roomId: "",
                cardId: null,
                projectId: '',
                milestoneId: null,
                buildingId: "",
                roomDealId: null,
                propertyCode: "CQBWYFY20201029001",
                propertyName: "绿地香花城四期1栋101",
                floor: "",
                roomUnit: "",
                projectType: "100",
                projectSubclassType: "100001",
                actualType: "街道民生居住",
                buildingArea: 108.00,
                unitConstructionArea: 100.00,
                apportionedArea:8,
                operation: "20",
                status: "10",
                propertySource: "10",
                constructionTime: "2020-10-20",
                suggestPrice: 11124355.00,
                areaCode: "440300-440304",
                areaName: "深圳市福田区沙头街道沙尾社区",
                address: "东城街101",
                propertyOwnership: "10",
                communityName: "440304004006",
                transferType: "",
                transferUnit: "",
                receiveTime: null,
                transferDesc: "",
                receiveId: null,
                receivePerson: null,
                longitude: null,
                latitude: null,
                remarks: "",
                roomCode: null,
                propertyStatus: "10",
                authorizationStatus: "0",
                splitMergeStatus: 0,
                isVr: "0",
                vrUrl: null,
                assetId: null,
                mapCoordinates: "114.085249,22.555933",
                roomStreet: "440304004",
                manageUnit: "02",
                occupier: null,
                manager: null,
                usedName: "",
                serviceLife: null,
                propertyRight: 1,
                planUse: null,
                parkingSpotNum: null

            }

            let baseDataRef = this.$refs.roomTable.$refs.baseData
            if(baseDataRef.projects){
                baseDataRef.baseForm.projectId = baseDataRef.projects[0].value
                this.$refs.roomTable.$refs.baseData.queryBuilding();
                this.$refs.roomTable.$refs.baseData.changeProjectType('10');
                this.$refs.roomTable.$refs.baseData.baseForm.projectSubclassType = '100001'
            }

        },
        ok() {
            this.$refs.roomTable.submitForm();
        },
        close(){
            this.dialogVisible = false;
        }

    }

}
